<!DOCTYPE html>
<html prefix="
og: http://ogp.me/ns#
article: http://ogp.me/ns/article#
" lang="zh_cn">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Alternative Social Buttons | vincent blog</title>
<link href="../../assets/css/all-nocdn.css" rel="stylesheet" type="text/css">
<link rel="alternate" type="application/rss+xml" title="RSS" href="../../rss.xml">
<link rel="canonical" href="https://wisonwang.github.io/pages/social_buttons/">
<!--[if lt IE 9]><script src="/assets/js/html5.js"></script><![endif]--><meta name="author" content="The Nikola Team">
<meta property="og:site_name" content="vincent blog">
<meta property="og:title" content="Alternative Social Buttons">
<meta property="og:url" content="https://wisonwang.github.io/pages/social_buttons/">
<meta property="og:description" content='Version:7.8.14




目录

The Default
ShareNice
SocialSharePrivacy
The Hard Way
The Easy Way





The Default
By Default, the themes provided with Nikola will add to your pages a "slide in" widget at
the'>
<meta property="og:type" content="article">
<meta property="article:published_time" content="2013-08-19T23:00:00-03:00">
<meta name="author" content="The Nikola Team">
<meta property="og:site_name" content="vincent blog">
<meta property="og:title" content="Alternative Social Buttons">
<meta property="og:url" content="https://wisonwang.github.io/pages/social_buttons/">
<meta property="og:description" content='Version:7.8.14




目录

The Default
ShareNice
SocialSharePrivacy
The Hard Way
The Easy Way





The Default
By Default, the themes provided with Nikola will add to your pages a "slide in" widget at
the'>
<meta property="og:type" content="article">
<meta property="article:published_time" content="2013-08-19T23:00:00-03:00">
</head>
<body>
    <section class="social"><ul>
<li><a href="../../index.html" title="Home"><i class="icon-home"></i></a></li>
            <li><a href="../../archive.html" title="文章存档"><i class="icon-archive"></i></a></li>
            <li><a href="../../categories/" title="标签"><i class="icon-tags"></i></a></li>
            <li><a href="../about" title="About"><i class="icon-about"></i></a></li>
            <li><a href="../../rss.xml" title="RSS 源"><i class="icon-rss"></i></a></li>
            <li><a href="https://twitter.com/wisonwang" title="My Twitter"><i class="icon-twitter"></i></a></li>
            <li><a href="https://github.com/wisonwang" title="My Github"><i class="icon-github"></i></a></li>

        </ul></section><section class="page-content"><div class="content" rel="main">
<article class="storypage" itemscope="itemscope" itemtype="http://schema.org/Article"><header><h1 class="p-name entry-title" itemprop="headline name">Alternative Social Buttons</h1>

        
    </header><div itemprop="articleBody text">
    <div>
<table class="docinfo" frame="void" rules="none">
<col class="docinfo-name">
<col class="docinfo-content">
<tbody valign="top"><tr class="version field">
<th class="docinfo-name">Version:</th>
<td class="field-body">7.8.14</td>
</tr></tbody>
</table>
<div class="contents alert alert-info pull-right topic" id="id1">
<p class="topic-title first">目录</p>
<ul class="simple">
<li><a class="reference internal" href="#the-default" id="id2">The Default</a></li>
<li><a class="reference internal" href="#sharenice" id="id3">ShareNice</a></li>
<li>
<a class="reference internal" href="#socialshareprivacy" id="id4">SocialSharePrivacy</a><ul>
<li><a class="reference internal" href="#the-hard-way" id="id5">The Hard Way</a></li>
<li><a class="reference internal" href="#the-easy-way" id="id6">The Easy Way</a></li>
</ul>
</li>
</ul>
</div>
<div class="section" id="the-default">
<h2><a class="toc-backref" href="#id2">The Default</a></h2>
<p>By Default, the themes provided with Nikola will add to your pages a "slide in" widget at
the bottom right of the page, provided by Addthis. This is the HTML code for that:</p>
<pre class="code html"><a name="rest_code_c872c315d7264737876d407b163fde6d-1"></a><span class="c">&lt;!-- Social buttons --&gt;</span>
<a name="rest_code_c872c315d7264737876d407b163fde6d-2"></a><span class="p">&lt;</span><span class="nt">div</span> <span class="na">id</span><span class="o">=</span><span class="s">"addthisbox"</span> <span class="na">class</span><span class="o">=</span><span class="s">"addthis_toolbox addthis_peekaboo_style</span>
<a name="rest_code_c872c315d7264737876d407b163fde6d-3"></a><span class="s">    addthis_default_style addthis_label_style addthis_32x32_style"</span><span class="p">&gt;</span>
<a name="rest_code_c872c315d7264737876d407b163fde6d-4"></a><span class="p">&lt;</span><span class="nt">a</span> <span class="na">class</span><span class="o">=</span><span class="s">"addthis_button_more"</span><span class="p">&gt;</span>Share<span class="p">&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
<a name="rest_code_c872c315d7264737876d407b163fde6d-5"></a><span class="p">&lt;</span><span class="nt">ul</span><span class="p">&gt;&lt;</span><span class="nt">li</span><span class="p">&gt;&lt;</span><span class="nt">a</span> <span class="na">class</span><span class="o">=</span><span class="s">"addthis_button_facebook"</span><span class="p">&gt;&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
<a name="rest_code_c872c315d7264737876d407b163fde6d-6"></a><span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;&lt;</span><span class="nt">a</span> <span class="na">class</span><span class="o">=</span><span class="s">"addthis_button_google_plusone_share"</span><span class="p">&gt;&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
<a name="rest_code_c872c315d7264737876d407b163fde6d-7"></a><span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;&lt;</span><span class="nt">a</span> <span class="na">class</span><span class="o">=</span><span class="s">"addthis_button_linkedin"</span><span class="p">&gt;&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
<a name="rest_code_c872c315d7264737876d407b163fde6d-8"></a><span class="p">&lt;</span><span class="nt">li</span><span class="p">&gt;&lt;</span><span class="nt">a</span> <span class="na">class</span><span class="o">=</span><span class="s">"addthis_button_twitter"</span><span class="p">&gt;&lt;/</span><span class="nt">a</span><span class="p">&gt;</span>
<a name="rest_code_c872c315d7264737876d407b163fde6d-9"></a><span class="p">&lt;/</span><span class="nt">ul</span><span class="p">&gt;</span>
<a name="rest_code_c872c315d7264737876d407b163fde6d-10"></a><span class="p">&lt;/</span><span class="nt">div</span><span class="p">&gt;</span>
<a name="rest_code_c872c315d7264737876d407b163fde6d-11"></a><span class="p">&lt;</span><span class="nt">script</span> <span class="na">src</span><span class="o">=</span><span class="s">"//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-4f7088a56bb93798"</span><span class="p">&gt;&lt;/</span><span class="nt">script</span><span class="p">&gt;</span>
<a name="rest_code_c872c315d7264737876d407b163fde6d-12"></a><span class="c">&lt;!-- End of social buttons --&gt;</span>
<a name="rest_code_c872c315d7264737876d407b163fde6d-13"></a>"""
</pre>
<p>You can change that using the <tt class="docutils literal">SOCIAL_BUTTONS_CODE</tt> option in your conf.py. In some cases, just
doing that will be enough but in others, it won't. This document tries to describe all the bits
involved in making this work correctly.</p>
<dl class="docutils">
<dt>Part 1: <tt class="docutils literal">SOCIAL_BUTTONS_CODE</tt>
</dt>
<dd>Social sharing services like addthis and others will provide you a HTML snippet.
If it is self-contained, then just setting <tt class="docutils literal">SOCIAL_BUTTONS_CODE</tt> may be enough.
Try :-)</dd>
<dt>Part 2: The theme</dt>
<dd>The <tt class="docutils literal">SOCIAL_BUTTONS_CODE</tt> HTML fragment will be embedded <em>somewhere</em> by the theme. Whether that
is the correct place or not is not something the theme author can truly know, so it is possible that
you may have to tweak the <tt class="docutils literal">base.html</tt> template to make it look good.</dd>
<dt>Part 3: <tt class="docutils literal">BODY_END</tt> and <tt class="docutils literal">EXTRA_HEAD_DATA</tt>
</dt>
<dd>
<p class="first">Some social sharing code requires JS execution that depends on JQuery being available
(example: <a class="reference external" href="https://github.com/panzi/SocialSharePrivacy">SocialSharePrivacy</a>). It's good
practice (and often, the only way that will work) to put those at the end of <tt class="docutils literal">&lt;BODY&gt;</tt>,
and one easy way to do that is to put them in <tt class="docutils literal">BODY_END</tt></p>
<p class="last">On the other hand, it's possible that it requires you to load some CSS files.
The right place for that is in the document's <tt class="docutils literal">&lt;HEAD&gt;</tt> so they should be added
in <tt class="docutils literal">EXTRA_HEAD_DATA</tt></p>
</dd>
<dt>Part 4: assets</dt>
<dd>For sharing code that doesn't rely on a social sharing service, you may need to add CSS, Image, or JS
files to your site</dd>
</dl>
</div>
<div class="section" id="sharenice">
<h2><a class="toc-backref" href="#id3">ShareNice</a></h2>
<p><a class="reference external" href="http://sharenice.org">Sharenice</a> is "written in order to provide social sharing features to
web developers and website administrators who wish to maintain and protect their users' privacy"
which sounds cool to me.</p>
<p>Let's go step by step into integrating the hosted version of ShareNice into a Nikola site.</p>
<p>For testing purposes, let's do it on a demo site:</p>
<pre class="literal-block">
$ nikola init --demo sharenice_test
A new site with example data has been created at sharenice_test.
See README.txt in that folder for more information.
$ cd sharenice_test/
</pre>
<p>To see what's going on, let's start Nikola in "auto mode". This should build the
site and open a web browser showing the default configuration, with the AddThis widget:</p>
<pre class="literal-block">
$ nikola auto -b
</pre>
<p>First, let's add the HTML snippet that will show the sharing options. In your conf.py, set this, which
is the HTML code suggested by ShareNice:</p>
<pre class="code python"><a name="rest_code_0346d77e72864d0189a7586209df62a8-1"></a><span class="n">SOCIAL_BUTTONS_CODE</span> <span class="o">=</span> <span class="s2">"""&lt;div id="shareNice" data-share-label="Share"</span>
<a name="rest_code_0346d77e72864d0189a7586209df62a8-2"></a><span class="s2">    data-color-scheme="black" data-icon-size="32" data-panel-bottom="plain"</span>
<a name="rest_code_0346d77e72864d0189a7586209df62a8-3"></a><span class="s2">    data-services="plus.google.com,facebook.com,digg.com,email,delicious.com,twitter.com"</span>
<a name="rest_code_0346d77e72864d0189a7586209df62a8-4"></a><span class="s2">    style="float:right"&gt;&lt;/div&gt;"""</span>
<a name="rest_code_0346d77e72864d0189a7586209df62a8-5"></a>
<a name="rest_code_0346d77e72864d0189a7586209df62a8-6"></a><span class="n">BODY_END</span> <span class="o">=</span> <span class="s2">"""&lt;script src="http://graingert.co.uk/shareNice/code.js"&gt;&lt;/script&gt;"""</span>
</pre>
<p>And you should now see a sharing box at the bottom right of the page.</p>
<p>Main problem remaining is that it doesn't really look good and integrated in the page layout.
I suggest changing the code to this which looks nicer, but still has some placement issues:</p>
<pre class="code python"><a name="rest_code_3b9032131fc74dc4b220d234cfa9cfd9-1"></a><span class="n">SOCIAL_BUTTONS_CODE</span> <span class="o">=</span> <span class="s2">"""&lt;div id="shareNice" data-share-label="Share"</span>
<a name="rest_code_3b9032131fc74dc4b220d234cfa9cfd9-2"></a><span class="s2">    data-color-scheme="black" data-icon-size="32" data-panel-bottom="plain"</span>
<a name="rest_code_3b9032131fc74dc4b220d234cfa9cfd9-3"></a><span class="s2">    data-services="plus.google.com,facebook.com,email,twitter.com"</span>
<a name="rest_code_3b9032131fc74dc4b220d234cfa9cfd9-4"></a><span class="s2">    style="position: absolute; left: 20px; top: 60px;"&gt;&lt;/div&gt;"""</span>
</pre>
<p>If anyone comes up with a better idea of styling/placement, just let me know ;-)</p>
<p>One bad bit of this so far is that you are now using a script from another site, and that
doesn't let Nikola perform as many optimizations to your page as it could.
So, if you really want to go the extra mile to save a few KB and round trips, you <em>could</em>
install your own copy from the <a class="reference external" href="https://github.com/mischat/shareNice">github repo</a> and
use that instead of the copy at sharenice.org.</p>
<p>Then, you can create your own theme inheriting from the one you are using and add the CSS
and JS files from ShareNice into your <tt class="docutils literal">bundles</tt> configuration so they are combined and
minified.</p>
</div>
<div class="section" id="socialshareprivacy">
<h2><a class="toc-backref" href="#id4">SocialSharePrivacy</a></h2>
<div class="section" id="the-hard-way">
<h3><a class="toc-backref" href="#id5">The Hard Way</a></h3>
<p><a class="reference external" href="https://github.com/panzi/SocialSharePrivacy">SocialSharePrivacy</a> is "a jQuery plugin that
lets you add social share buttons to your website that don't allow the social sites to track
your users." Nice!</p>
<p>Let's go step-by-step into integrating SocialSharePrivacy into a Nikola site. To improve
privacy, they recommend you not use the hosted service so we'll do it the hard way, by
getting and distributing everything in our own site.</p>
<p><a class="reference external" href="https://github.com/panzi/SocialSharePrivacy">https://github.com/panzi/SocialSharePrivacy</a></p>
<p>For testing purposes, let's do it on a demo site:</p>
<pre class="literal-block">
$ nikola init --demo ssp_test
A new site with example data has been created at ssp_test.
See README.txt in that folder for more information.
$ cd ssp_test/
</pre>
<p>To see what's going on, let's start Nikola in "auto mode". This should build the
site and open a web browser showing the default configuration, with the AddThis widget:</p>
<pre class="literal-block">
$ nikola auto -b
</pre>
<p>Now, download <a class="reference external" href="https://github.com/panzi/SocialSharePrivacy/archive/master.zip">the current version</a>
and unzip it. You will have a <tt class="docutils literal"><span class="pre">SocialSharePrivacy-master</span></tt> folder with lots of stuff in it.</p>
<p>First, we need to build it (this requires a working and modern uglifyjs, this may not be easy):</p>
<pre class="literal-block">
$ cd SocialSharePrivacy-master
$ sh build.sh -m gplus,twitter,facebook,mail -s "/assets/css/socialshareprivacy.css" -a off
</pre>
<p>You will now have several files in a <tt class="docutils literal">build</tt> folder. We need to bring them into the site:</p>
<pre class="literal-block">
$ cp -Rv SocialSharePrivacy-master/build/* files/
$ cp -R SocialSharePrivacy-master/images/ files/assets/
</pre>
<p>Edit your <tt class="docutils literal">conf.py</tt>:</p>
<pre class="code python"><a name="rest_code_9cdcaa08b4924795b25015eecf70fe1f-1"></a><span class="n">BODY_END</span> <span class="o">=</span> <span class="s2">"""</span>
<a name="rest_code_9cdcaa08b4924795b25015eecf70fe1f-2"></a><span class="s2">&lt;script src="/javascripts/jquery.socialshareprivacy.min.js"&gt;&lt;/script&gt;</span>
<a name="rest_code_9cdcaa08b4924795b25015eecf70fe1f-3"></a><span class="s2">&lt;script&gt;</span>
<a name="rest_code_9cdcaa08b4924795b25015eecf70fe1f-4"></a><span class="s2">$(document).ready(function () {</span>
<a name="rest_code_9cdcaa08b4924795b25015eecf70fe1f-5"></a><span class="s2">    $('.share').socialSharePrivacy();</span>
<a name="rest_code_9cdcaa08b4924795b25015eecf70fe1f-6"></a><span class="s2">});</span>
<a name="rest_code_9cdcaa08b4924795b25015eecf70fe1f-7"></a><span class="s2">&lt;/script&gt;</span>
<a name="rest_code_9cdcaa08b4924795b25015eecf70fe1f-8"></a><span class="s2">"""</span>
<a name="rest_code_9cdcaa08b4924795b25015eecf70fe1f-9"></a>
<a name="rest_code_9cdcaa08b4924795b25015eecf70fe1f-10"></a><span class="n">SOCIAL_BUTTONS_CODE</span> <span class="o">=</span> <span class="s2">"""&lt;div class="share"&gt;&lt;/div&gt;"""</span>
</pre>
<p>In my experience this produces a broken, duplicate, semi-working thing. YMMV and if you make it work correctly, let me know how :-)</p>
</div>
<div class="section" id="the-easy-way">
<h3><a class="toc-backref" href="#id6">The Easy Way</a></h3>
<p>Go to <a class="reference external" href="http://panzi.github.io/SocialSharePrivacy/">http://panzi.github.io/SocialSharePrivacy/</a> and use the provided form to get the code. Make sure you check "I already use JQuery"
if you are using one of the themes that require it, like site or default, select the services you want, and use your disqus name if
you have one.</p>
<p>It will give you 3 code snippets:</p>
<dl class="docutils">
<dt>"Insert this once in the head of your page"</dt>
<dd>Put it in <tt class="docutils literal">BODY_END</tt>
</dd>
<dt>"Insert this wherever you want a share widget displayed"</dt>
<dd>Put it in <tt class="docutils literal">SOCIAL_BUTTONS_CODE</tt>
</dd>
<dt>"Insert this once anywhere after the other code"</dt>
<dd>Put it in <tt class="docutils literal">BODY_END</tt>
</dd>
</dl>
<p>That should give you a working integration (not tested)</p>
</div>
</div>
</div>
    </div>
</article><footer id="footer"><p>Contents © 2020         <a href="mailto:fangfu2012@gmail.com">vincent wang</a> - Powered by         <a href="https://getnikola.com" rel="nofollow">Nikola</a>         </p>
            
        </footer>
</div>
    </section><script src="../../assets/js/all-nocdn.js" type="text/javascript"></script><script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script><script type="text/x-mathjax-config">
    MathJax.Hub.Config({tex2jax: {inlineMath: [['$latex ','$'], ['\\(','\\)']]}});
    </script><script type="text/javascript">
            $(function(){
                $('.timeago').timeago();
            });
        </script>
</body>
</html>
